package com.xieli.invitesdk.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.xieli.invitesdk.InviteRequest
import com.xieli.invitesdk.InviteService
import com.xieli.invitesdk.bean.invitecodeData
import com.xieli.invitesdk.OkhttpModule
import com.xieli.invitesdk.bean.inviterlistsData
/**
 * @Auther sr
 * @Date 2023/9
 * @Description 邀请有礼ViewModel
 */
class InviteViewModel: ViewModel() {

    val mService: InviteService = OkhttpModule.retrofit(OkhttpModule.BASE_URL).create(InviteService::class.java)
    val inviteRequest = InviteRequest(mService)

    private val _invitedata = MutableLiveData<invitecodeData>()
    val invitedata: LiveData<invitecodeData> = _invitedata

    private val _inviterLists = MutableLiveData<inviterlistsData>()
    val inviterLists: LiveData<inviterlistsData> = _inviterLists

    /**
     * 获取邀请码
     * @param usertoken String
     */
    suspend fun getInvitecode(usertoken: String) {
        inviteRequest.invitecode(usertoken)
            .let {
                if (it.isSuccess())
                    _invitedata.postValue(it)
            }
    }
    /**
     * 获取邀请成功列表
     * @param usertoken String
     */
    suspend fun inviterLists(usertoken: String) {
        inviteRequest.inviterLists(usertoken)
            .let {
                if (it.isSuccess())
                    _inviterLists.postValue(it)
            }
    }


}